function initPage(baseInfoJson,diseaseDiagInfoJson){
	var basePath = $("#basePath").val();
	var diagTypes = baseInfoJson['diagTypes'];//诊断类型
	
	var diseaseStates = baseInfoJson['inHospitalizationDiseaseStates'];//治疗结果
	
	var treatmentResults = baseInfoJson['treatmentResults'];//治疗结果
	var mainDiagRecord = diseaseDiagInfoJson['mainDiagRecord'];//主要诊断
	var diseaseDiagRecords = diseaseDiagInfoJson['diseaseDiagRecords'];//诊断记录集合
	
	$("select").each(function(){
		$(this).append("<option value=''>--请选择--</option>");
		
	});
	
	$("select[name$='.diagTypeCode']").each(function(){
		var options = "";
		for(var index in diagTypes){
			var diagType = diagTypes[index];
	    	options+="<option value='"+diagType.uniq_code+"'>"+diagType.label+"</option>"
	    } 
       $(this).append(options);
       
	});
	
	$("select[name$='.inHospitalDiseaseStateCode']").each(function(){
		var options = "";
		for(var index in diseaseStates){
			var diseaseState = diseaseStates[index];
	    	options+="<option value='"+diseaseState.uniq_code+"'>"+diseaseState.label+"</option>";
	    } 
       $(this).append(options);
       
	});
	
	$("select[name$='.treatResultCode']").each(function(){
		var options = "";
		for(var index in treatmentResults){
			var treatmentResult = treatmentResults[index];
	    	options+="<option value='"+treatmentResult.uniq_code+"'>"+treatmentResult.label+"</option>";
	    } 
       $(this).append(options);
       
	});
	
	for(var index in diseaseDiagRecords){
		var diseaseDiagRecord = diseaseDiagRecords[index];
		var add_content = addDiagRecord();
		add_content.find("span[class='otherDiagTypeShow']").html(diseaseDiagRecord.diagTypeName);
		add_content.find("input[name$='.diagTypeCode']").val(diseaseDiagRecord.diagTypeCode);
		add_content.find("input[name$='.diagTypeName']").val(diseaseDiagRecord.diagTypeName);
		var diseaseDiagOriginalCode = diseaseDiagRecord.diseaseDiagOriginalCode;
		var diseaseDiagOriginalDesc = diseaseDiagRecord.diseaseDiagOriginalDesc
		var ohterDiagOriginalDiagShow = null;
		if(diseaseDiagOriginalCode){
			ohterDiagOriginalDiagShow = diseaseDiagOriginalCode+'['+diseaseDiagOriginalDesc+']';
		}else{
			ohterDiagOriginalDiagShow = diseaseDiagOriginalDesc;
		}
		add_content.find("span[class='ohterDiagOriginalDiagShow']").html(ohterDiagOriginalDiagShow);
		add_content.find("input[name$='.diseaseDiagOriginalDesc']").val(diseaseDiagOriginalDesc);
		add_content.find("input[name$='.diseaseDiagOriginalCode']").val(diseaseDiagOriginalCode);
		
		add_content.find("span[class='otherDiagShow']").html(diseaseDiagRecord.diseaseDiagCode);
		add_content.find("input[name$='.diseaseDiagCode']").val(diseaseDiagRecord.diseaseDiagCode);
		add_content.find("input[name$='.diseaseDiagName']").val(diseaseDiagRecord.diseaseDiagName);
		for(var extraIndex in diseaseDiagRecord.diseaseExtraDiagRecords){
			var extraDiagRecord = diseaseDiagRecord.diseaseExtraDiagRecords[extraIndex];
			add_content.find("input[name$='.diseaseExtraDiagRecords["+extraIndex+"].diseaseExtraDiagCode']").val(extraDiagRecord.diseaseExtraDiagCode);
			add_content.find("input[name$='.diseaseExtraDiagRecords["+extraIndex+"].diseaseExtraDiagName']").val(extraDiagRecord.diseaseExtraDiagName);
			add_content.find("input[name$='.diseaseExtraDiagRecords["+extraIndex+"].isExtraMainCode']").val(extraDiagRecord.isExtraMainCode);
			add_content.find("input[name$='.diseaseExtraDiagRecords["+extraIndex+"].isExtraMainName']").val(extraDiagRecord.isExtraMainName);
		}
		
		add_content.find("span[class='otherDiagInHospitalDiseaseStateShow']").html(diseaseDiagRecord.inHospitalDiseaseStateName);
		add_content.find("input[name$='.inHospitalDiseaseStateCode']").val(diseaseDiagRecord.inHospitalDiseaseStateCode);
		add_content.find("input[name$='.inHospitalDiseaseStateName']").val(diseaseDiagRecord.inHospitalDiseaseStateName);
		
		add_content.find("span[class='otherDiagTreatResultShow']").html(diseaseDiagRecord.treatResultName);
		add_content.find("input[name$='.treatResultCode']").val(diseaseDiagRecord.treatResultCode);
		add_content.find("input[name$='.treatResultName']").val(diseaseDiagRecord.treatResultName);
		
		add_content.find("span[class='otherDiagSortIndex']").html(diseaseDiagRecord.diagSortIndex);
		add_content.find("input[name$='.diagSortIndex']").val(diseaseDiagRecord.diagSortIndex);
		
    } 
	

	parent.document.getElementById("mainContent").height=document.body.scrollHeight;
};
function deleteDiseaseDiagRecord(obj){
	if(!confirm("确定要删除吗？"))
	 {
		return false;
	 }
	$(obj).parent().parent().remove();
}


//显示修改门诊诊断数据Layer
var layerUpdateOutpatientDiagIndex
function layerUpdateOutpatientDiag(obj){
	var basePath = $("#basePath").val();
	var add_content=$("#update_outpatient_diag_div").clone();
	var content=$(obj).parent().parent();
	add_content.find("form").attr("id","update_outpatient_diag_form");
	var title = "编辑门诊诊断";
	layerUpdateOutpatientDiagIndex = layer.open({
		  type: 1,
		  title:title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['820px', '450px'], //宽高
		  offset:'50px',
		  content: add_content.html(),
		  success: function(layero, index){
			  $("#update_outpatient_diag_form .outpatientOriginalDiagShow").html(content.find(".outpatientOriginalDiagShow").html());
			  var outpatientDiagCode = content.find("input[name='outpatientDiagRecord.diseaseDiagCode']").val();
			  var outpatientDiagName = content.find("input[name='outpatientDiagRecord.diseaseDiagName']").val();
			  var outpatientDiagShow = null;
			  if(outpatientDiagCode==''){
				  outpatientDiagShow=null;
			  }else{
				  outpatientDiagShow = outpatientDiagCode+'['+outpatientDiagName+']';
			  }
			  $("#update_outpatient_diag_form input[name='outpatientDiagShow']").val(outpatientDiagShow);
			  $("#update_outpatient_diag_form input[name='outpatientDiagCode']").val(outpatientDiagCode);
			  $("#update_outpatient_diag_form input[name='outpatientDiagName']").val(outpatientDiagName);
			  $.each($("#update_outpatient_diag_form input[data-type='diseaseDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
							}
						});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#update_outpatient_diag_form input[data-type='allDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_all_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
							}
						});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  for (var int = 0; int < 6; int++) {
				  var outpatientExtraDiagCode = content.find("input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val();
				  var outpatientExtraDiagName = content.find("input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val();
				  var isExtraMainCode = content.find("input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val();
				  
				  var outpatientExtraDiagShow = null;
				  if(outpatientExtraDiagCode ==''){
					  outpatientExtraDiagShow = null;
				  }else{
					  outpatientExtraDiagShow = outpatientExtraDiagCode+'['+outpatientExtraDiagName+']';
				  }
				  $("#update_outpatient_diag_form input[name='outpatientExtraDiag"+int+"Show']").val(outpatientExtraDiagShow);
				  $("#update_outpatient_diag_form input[name='outpatientExtraDiag"+int+"Code']").val(outpatientExtraDiagCode);
				  $("#update_outpatient_diag_form input[name='outpatientExtraDiag"+int+"Name']").val(outpatientExtraDiagName);
				  if(isExtraMainCode && isExtraMainCode == '1'){
					  $("#update_outpatient_diag_form input[name='isExtraMain"+int+"Code']").prop("checked",true);;
					  
				  }
			  }
			  var validator = $("#update_outpatient_diag_form").validate({
					errorElement: "title",
					ignoreTitle: true,
					submitHandler : function(){
						layerUpdateOutpatientSubmit();
					},
					/*rules:{
						outpatientDiagShow: {
							required: true,
			                minlength: 5
			            }
						
					},
					*/
				});
		  }
		});
}

function layerUpdateOutpatientClick(){
	$("#update_outpatient_diag_form").submit();
}


function layerUpdateOutpatientSubmit(){
	var outpatientDiagCode = $("#update_outpatient_diag_form input[name='outpatientDiagCode']").val();
	var outpatientDiagName = $("#update_outpatient_diag_form input[name='outpatientDiagName']").val();
	var outpatientDiagShow = $("#update_outpatient_diag_form input[name='outpatientDiagShow']").val();
	if(outpatientDiagCode==''){
		outpatientDiagShow=null;
	}else{
		outpatientDiagShow = outpatientDiagCode;
	}
	$("#diseaseDiagInfoForm span[class='outpatientDiagShow']").html(outpatientDiagShow);
	$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseDiagName']").val(outpatientDiagName);
	$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseDiagCode']").val(outpatientDiagCode);
	
	for (var int = 0; int < 6; int++) {
		var outpatientExtraDiagCode = $("#update_outpatient_diag_form input[name='outpatientExtraDiag"+int+"Code']").val();
		var outpatientExtraDiagName = $("#update_outpatient_diag_form input[name='outpatientExtraDiag"+int+"Name']").val();
		var isChecked = $("#update_outpatient_diag_form input[name='isExtraMain"+int+"Code']").prop("checked");
		
		$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val(outpatientExtraDiagCode);
		$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val(outpatientExtraDiagName);
		var isExtraMainCode = '1';
		var isExtraMainName = '是';
		if(isChecked){
			$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(isExtraMainCode);
			$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(isExtraMainName);
			
		}else{
			$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(null);
			$("#diseaseDiagInfoForm input[name='outpatientDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(null);
		}
	}
	layer.close(layerUpdateOutpatientDiagIndex);
}


//显示修改主要诊断数据Layer
var layerUpdateMainDiagIndex
function layerUpdateMainDiag(obj){
	var basePath = $("#basePath").val();
	var add_content=$("#update_main_diag_div").clone();
	var content=$(obj).parent().parent();
	add_content.find("form").attr("id","update_main_diag_form");
	var title = "编辑主要诊断";
	layerUpdateMainDiagIndex = layer.open({
	
		  type: 1,
		  title:title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['820px', '500px'], //宽高
		  offset:'50px',
		  content: add_content.html(),
		  success: function(layero, index){
			  $("#update_main_diag_form .mainDiagOriginalDiagShow").html(content.find(".mainDiagOriginalDiagShow").html());
			  var mainDiagCode = content.find("input[name='mainDiagRecord.diseaseDiagCode']").val();
			  var mainDiagName = content.find("input[name='mainDiagRecord.diseaseDiagName']").val();
			  var mainDiagShow = null;
			  if(mainDiagCode==''){
				  mainDiagShow=null;
			  }else{
				  mainDiagShow = mainDiagCode+'['+mainDiagName+']';
			  }
			  $("#update_main_diag_form input[name='mainDiagShow']").val(mainDiagShow);
			  $("#update_main_diag_form input[name='mainDiagCode']").val(mainDiagCode);
			  $("#update_main_diag_form input[name='mainDiagName']").val(mainDiagName);
			  $.each($("#update_main_diag_form input[data-type='diseaseDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							$.ajax({
								url: basePath + "base_info/ajax_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
								if(data.length > 0){
									response( $.map( data, function( item ) {
										return {
											label:item.uniq_code+'['+item.label+']',
											uniq_code:item.uniq_code,
											uniq_name:item.label
										}
									}));
								}else{
									response([[]]);
								}
							}
						});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					        // event 是当前事件对象
					        
					        // ui对象仅有一个item属性，它表示当前选择的菜单项对应的数据源对象
					        // 该对象具有label和value属性，以及其它自定义(如果有的话)的属性
					        // 如果当前没有选择的菜单项，这item属性为null
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#update_main_diag_form input[data-type='allDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							$.ajax({
								url: basePath + "base_info/ajax_all_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
								if(data.length > 0){
									response( $.map( data, function( item ) {
										return {
											label:item.uniq_code+'['+item.label+']',
											uniq_code:item.uniq_code,
											uniq_name:item.label
										}
									}));
								}else{
									response([[]]);
								}
							}
						});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					        // event 是当前事件对象
					        
					        // ui对象仅有一个item属性，它表示当前选择的菜单项对应的数据源对象
					        // 该对象具有label和value属性，以及其它自定义(如果有的话)的属性
					        // 如果当前没有选择的菜单项，这item属性为null
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#update_main_diag_form select[name$='mainDiagRecord.inHospitalDiseaseStateCode'],[name$='mainDiagRecord.treatResultCode']"),function(i,item) {
					$(item).change(function(){
				   		var eventObj = $(this);
				   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
				   		
				   		if(eventObj.val()!=""){
				   			var name=eventObj.find("option:selected").text();
				   			eventObj.next("input[name='"+nameObjName+"']").val(name);
				   		}else{
				   			eventObj.next("input[name='"+nameObjName+"']").val("");
				   		}
				   	});
			  });
			  var inHospitalDiseaseStateCode = content.find("input[name='mainDiagRecord.inHospitalDiseaseStateCode']").val();
			  var inHospitalDiseaseStateName = content.find("input[name='mainDiagRecord.inHospitalDiseaseStateName']").val();
			  if(inHospitalDiseaseStateCode != ''){
				  	var selectedIndex = $("#update_main_diag_form select[name='mainDiagRecord.inHospitalDiseaseStateCode'] option[value='"+inHospitalDiseaseStateCode+"']").first().index();
					if (selectedIndex == -1) {
						var option = "<option selected value='" + inHospitalDiseaseStateCode + "'>" + inHospitalDiseaseStateName + "</option>";
						$("#update_main_diag_form select[name$='mainDiagRecord.inHospitalDiseaseStateCode']").append(option);
					} else {
						$("#update_main_diag_form select[name$='mainDiagRecord.inHospitalDiseaseStateCode']").get(0).selectedIndex = selectedIndex;
					}
			  }
			  $("#update_main_diag_form select[name='mainDiagRecord.inHospitalDiseaseStateCode']").next("input[name$='inHospitalDiseaseStateName']").val(inHospitalDiseaseStateName);
			  
			  var treatResultCode = content.find("input[name='mainDiagRecord.treatResultCode']").val();
			  var treatResultName = content.find("input[name='mainDiagRecord.treatResultName']").val();
			  if(treatResultCode != ''){
				  	var selectedIndex = $("#update_main_diag_form select[name='mainDiagRecord.treatResultCode'] option[value='"+treatResultCode+"']").first().index();
					if (selectedIndex == -1) {
						var option = "<option selected value='" + treatResultCode + "'>" + treatResultName + "</option>";
						$("#update_main_diag_form select[name$='mainDiagRecord.treatResultCode']").append(option);
					} else {
						$("#update_main_diag_form select[name$='mainDiagRecord.treatResultCode']").get(0).selectedIndex = selectedIndex;
					}
			  }
			  $("#update_main_diag_form select[name='mainDiagRecord.treatResultCode']").next("input[name$='treatResultName']").val(treatResultName);
			  
			  for (var int = 0; int < 6; int++) {
				  var mainExtraDiagCode = content.find("input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val();
				  var mainExtraDiagName = content.find("input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val();
				  var mainExtraDiagShow = null;
				  if(mainExtraDiagCode ==''){
					  mainExtraDiagShow = null;
				  }else{
					  mainExtraDiagShow = mainExtraDiagCode+'['+mainExtraDiagName+']';
				  }
				  $("#update_main_diag_form input[name='mainExtraDiag"+int+"Show']").val(mainExtraDiagShow);
				  $("#update_main_diag_form input[name='mainExtraDiag"+int+"Code']").val(mainExtraDiagCode);
				  $("#update_main_diag_form input[name='mainExtraDiag"+int+"Name']").val(mainExtraDiagName);
				  var isExtraMainCode = content.find("input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val();
				  if(isExtraMainCode && isExtraMainCode == '1'){
					  $("#update_main_diag_form input[name='isExtraMain"+int+"Code']").prop("checked",true);;
					  
				  }
			  }
			  var validator = $("#update_main_diag_form").validate({
					errorElement: "title",
					ignoreTitle: true,
					submitHandler : function(){
						layerUpdateMainSubmit();
						/*return false;*/
					},
					/*rules:{
						mainDiagShow: {
							required: true,
			                minlength: 5
			            }
						
					},*/
					
				});
		}
	});
}

function layerUpdateMainClick(){
	$("#update_main_diag_form").submit();
}

function layerUpdateMainSubmit(){
	var mainDiagCode = $("#update_main_diag_form input[name='mainDiagCode']").val();
	var mainDiagName = $("#update_main_diag_form input[name='mainDiagName']").val();
	var mainDiagShow = null;
	if(mainDiagCode==''){
		mainDiagShow=null;
	}else{
		mainDiagShow = mainDiagCode;
	}
	$("#diseaseDiagInfoForm span[class='mainDiagShow']").html(mainDiagShow);
	$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseDiagName']").val(mainDiagName);
	$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseDiagCode']").val(mainDiagCode);
	
	var inHospitalDiseaseStateCode = $("#update_main_diag_form select[name='mainDiagRecord.inHospitalDiseaseStateCode']").val();
	var inHospitalDiseaseStateName = $("#update_main_diag_form input[name='mainDiagRecord.inHospitalDiseaseStateName']").val();
	$("#diseaseDiagInfoForm span[class='mainDiagInHospitalDiseaseStateShow']").html(inHospitalDiseaseStateName);
	$("#diseaseDiagInfoForm input[name='mainDiagRecord.inHospitalDiseaseStateCode']").val(inHospitalDiseaseStateCode);
	$("#diseaseDiagInfoForm input[name='mainDiagRecord.inHospitalDiseaseStateName']").val(inHospitalDiseaseStateName);
	
	var treatResultCode = $("#update_main_diag_form select[name='mainDiagRecord.treatResultCode']").val();
	var treatResultName = $("#update_main_diag_form input[name='mainDiagRecord.treatResultName']").val();
	$("#diseaseDiagInfoForm span[class='mainDiagTreatResultShow']").html(treatResultName);
	$("#diseaseDiagInfoForm input[name='mainDiagRecord.treatResultCode']").val(treatResultCode);
	$("#diseaseDiagInfoForm input[name='mainDiagRecord.treatResultName']").val(treatResultName);
	for (var int = 0; int < 6; int++) {
		var mainExtraDiagCode = $("#update_main_diag_form input[name='mainExtraDiag"+int+"Code']").val();
		var mainExtraDiagName = $("#update_main_diag_form input[name='mainExtraDiag"+int+"Name']").val();
		var isChecked = $("#update_main_diag_form input[name='isExtraMain"+int+"Code']").prop("checked");
		$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val(mainExtraDiagCode);
		$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val(mainExtraDiagName);
		
		var isExtraMainCode = '1';
		var isExtraMainName = '是';
		if(isChecked){
			$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(isExtraMainCode);
			$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(isExtraMainName);
			
		}else{
			$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(null);
			$("#diseaseDiagInfoForm input[name='mainDiagRecord.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(null);
		}
	}
	
	
	layer.close(layerUpdateMainDiagIndex);
}


//显示新增诊断数据Layer
var layerCreateDiagIndex
function layerCreateDiag(obj){
	var basePath = $("#basePath").val();
	var add_content=$("#create_diag_div").clone();
	var content=$(obj).parent().parent();
	add_content.find("form").attr("id","create_diag_form");
	var title = "新增诊断";
	layerCreateDiagIndex = layer.open({
		
		  type: 1,
		  title:title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['820px', '550px'], //宽高
		  offset:'50px',
		  content: add_content.html(),
		  success: function(layero, index){
			 
			  var selectedIndex = $("#create_diag_form select[name='otherDiag.diagTypeCode'] option[value='A']").first().index();
				
			  $("#create_diag_form select[name='otherDiag.diagTypeCode']").get(0).selectedIndex = selectedIndex;
			
			  $("#create_diag_form select[name='otherDiag.diagTypeCode']").next("input[name$='.diagTypeName']").val("其他诊断");
			  
			  $.each($("#create_diag_form input[data-type='diseaseDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
							}
						});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#create_diag_form input[data-type='allDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_all_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#create_diag_form select[name$='otherDiag.diagTypeCode'],[name$='otherDiagRecord.inHospitalDiseaseStateCode'],[name$='otherDiagRecord.treatResultCode']"),function(i,item) {
					$(item).change(function(){
				   		var eventObj = $(this);
				   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
				   		
				   		if(eventObj.val()!=""){
				   			var name=eventObj.find("option:selected").text();
				   			eventObj.next("input[name='"+nameObjName+"']").val(name);
				   		}else{
				   			eventObj.next("input[name='"+nameObjName+"']").val("");
				   		}
				   	});
			  });
			  
			  var validator = $("#create_diag_form").validate({
					errorElement: "title",
					ignoreTitle: true,
					submitHandler : function(){
						layerCreateOtherDiagSubmit();
						/*return false;*/
					},
					rules:{
						'otherDiag.diagTypeCode': {
							required: true
			            },
						'otherDiag.diagShow': {
							required: true,
			                minlength: 5
			            },
			            'otherDiag.diagSortIndex': {
			            	digits:true,
			            	range:[1,1000]
			            }
						
					},
					
				});
		}
	});
}

function layerCreateOtherDiagClick(){
	$("#create_diag_form").submit();
}

function layerCreateOtherDiagSubmit(){
	var content = addDiagRecord();
	
	var diagTypeCode = $("#create_diag_form select[name='otherDiag.diagTypeCode']").val();
	var diagTypeName = $("#create_diag_form input[name='otherDiag.diagTypeName']").val();
	content.find("span[class='otherDiagTypeShow']").html(diagTypeName);
	content.find("input[name$='.diagTypeCode']").val(diagTypeCode);
	content.find("input[name$='.diagTypeName']").val(diagTypeName);
	
	
	var otherDiagCode = $("#create_diag_form input[name='otherDiag.diagCode']").val();
	var otherDiagName = $("#create_diag_form input[name='otherDiag.diagName']").val();
	var otherDiagShow = null;
	if(otherDiagCode==''){
		otherDiagShow=null;
	}else{
		otherDiagShow = otherDiagCode;
	}
	content.find("span[class='otherDiagShow'] ").html(otherDiagShow);
	content.find("input[name$='.diseaseDiagCode']").val(otherDiagCode);
	content.find("input[name$='.diseaseDiagName']").val(otherDiagName);
	for (var int = 0; int < 6; int++) {
		var otherExtraDiagCode = $("#create_diag_form input[name='otherExtraDiag"+int+"Code']").val();
		var otherExtraDiagName = $("#create_diag_form input[name='otherExtraDiag"+int+"Name']").val();
		var isChecked = $("#create_diag_form input[name='isExtraMain"+int+"Code']").prop("checked");
		
		content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val(otherExtraDiagCode);
		content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val(otherExtraDiagName);
		var isExtraMainCode = '1';
		var isExtraMainName = '是';
		if(isChecked){
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(isExtraMainCode);
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(isExtraMainName);
			
		}else{
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(null);
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(null);
		}
	}
	var inHospitalDiseaseStateCode = $("#create_diag_form select[name$='.inHospitalDiseaseStateCode']").val();
	var inHospitalDiseaseStateName = $("#create_diag_form input[name$='.inHospitalDiseaseStateName']").val();
	content.find("span[class='otherDiagInHospitalDiseaseStateShow']").html(inHospitalDiseaseStateName);
	content.find("input[name$='.inHospitalDiseaseStateCode']").val(inHospitalDiseaseStateCode);
	content.find("input[name$='.inHospitalDiseaseStateName']").val(inHospitalDiseaseStateName);
	
	var treatResultCode = $("#create_diag_form select[name$='.treatResultCode']").val();
	var treatResultName = $("#create_diag_form input[name$='.treatResultName']").val();
	content.find("span[class='otherDiagTreatResultShow']").html(treatResultName);
	content.find("input[name$='.treatResultCode']").val(treatResultCode);
	content.find("input[name$='.treatResultName']").val(treatResultName);
	var diagSortIndex = $("#create_diag_form input[name='otherDiag.diagSortIndex']").val();
	content.find("input[name$='.diagSortIndex']").val(diagSortIndex);
	content.find("span[class='otherDiagSortIndex']").html(diagSortIndex);
	layer.close(layerCreateDiagIndex);
}

function addDiagRecord(){
	var basePath = $("#basePath").val();
	var diseaseDiagCountOjb = $("#diseaseDiagCount");
	var count = parseInt(diseaseDiagCountOjb.val());
	var add_content=$("#addDiagTr").clone();
	add_content.removeAttr("id");
	
	 $.each(add_content.find("input[name^='diseaseDiagRecords[0].']"), function(i,item) {    
    	var inputName = $(item).attr("name");
    	var changeName = inputName.replace("diseaseDiagRecords[0].","diseaseDiagRecords["+count+"].");
        $(item).attr("name",changeName);
    });

	
	$("#diseaseDiagTable tbody").append(add_content);
	diseaseDiagCountOjb.val(count +1);
	return add_content;
}

//显示编辑诊断数据Layer
var layerUpdateDiagIndex
function layerUpdateDiag(obj){
	var basePath = $("#basePath").val();
	var add_content=$("#update_diag_div").clone();
	var content=$(obj).parent().parent();
	add_content.find("form").attr("id","update_diag_form");
	var title = "编辑诊断";
	layerUpdateDiagIndex = layer.open({
		
		  type: 1,
		  title:title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['820px', '550px'], //宽高
		  offset:'50px',
		  content: add_content.html(),
		  success: function(layero, index){
			  var diagTypeCode = content.find("input[name$='.diagTypeCode']").val();
			  var diagTypeName = content.find("input[name$='.diagTypeName']").val();
			  if(diagTypeCode != ''){
				  	var selectedIndex = $("#update_diag_form select[name='otherDiag.diagTypeCode'] option[value='"+diagTypeCode+"']").first().index();
					if (selectedIndex == -1) {
						var option = "<option selected value='" + diagTypeCode + "'>" + diagTypeName + "</option>";
						$("#update_diag_form select[name$='otherDiag.diagTypeCode']").append(option);
					} else {
						$("#update_diag_form select[name='otherDiag.diagTypeCode']").get(0).selectedIndex = selectedIndex;
					}
			  }
			  $("#update_diag_form select[name='otherDiag.diagTypeCode']").next("input[name$='.diagTypeName']").val(diagTypeName);
			  
			  $("#update_diag_form .otherDiagOriginalShow").html(content.find(".ohterDiagOriginalDiagShow").html());
			  var otherDiagCode = content.find("input[name$='.diseaseDiagCode']").val();
			  var otherDiagName = content.find("input[name$='.diseaseDiagName']").val();
			  var otherDiagShow = null;
			  if(otherDiagCode==''){
				  otherDiagShow=null;
			  }else{
				  otherDiagShow = otherDiagCode+'['+otherDiagName+']';
			  }
			  $("#update_diag_form input[name='otherDiag.diagShow']").val(otherDiagShow);
			  $("#update_diag_form input[name='otherDiag.diagCode']").val(otherDiagCode);
			  $("#update_diag_form input[name='otherDiag.diagName']").val(otherDiagName);
			  

			  for (var int = 0; int < 6; int++) {
				  var otherExtraDiagCode = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val();
				  var otherExtraDiagName = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val();
				  var otherExtraDiagShow = null;
				  if(otherExtraDiagCode ==''){
					  otherExtraDiagShow = null;
				  }else{
					  otherExtraDiagShow = otherExtraDiagCode+'['+otherExtraDiagName+']';
				  }
				  $("#update_diag_form input[name='otherExtraDiag"+int+"Show']").val(otherExtraDiagShow);
				  $("#update_diag_form input[name='otherExtraDiag"+int+"Code']").val(otherExtraDiagCode);
				  $("#update_diag_form input[name='otherExtraDiag"+int+"Name']").val(otherExtraDiagName);
				  
				  var isExtraMainCode = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val();
				  if(isExtraMainCode && isExtraMainCode == '1'){
					  $("#update_diag_form input[name='isExtraMain"+int+"Code']").prop("checked",true);;
					  
				  }
				  
			  }
			  $.each($("#update_diag_form input[data-type='diseaseDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#update_diag_form input[data-type='allDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_all_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  $.each($("#update_diag_form select[name$='otherDiag.diagTypeCode'],[name$='otherDiagRecord.inHospitalDiseaseStateCode'],[name$='otherDiagRecord.treatResultCode']"),function(i,item) {
					$(item).change(function(){
				   		var eventObj = $(this);
				   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
				   		
				   		if(eventObj.val()!=""){
				   			var name=eventObj.find("option:selected").text();
				   			eventObj.next("input[name='"+nameObjName+"']").val(name);
				   		}else{
				   			eventObj.next("input[name='"+nameObjName+"']").val("");
				   		}
				   	});
			  });
			  var inHospitalDiseaseStateCode = content.find("input[name$='.inHospitalDiseaseStateCode']").val();
			  var inHospitalDiseaseStateName = content.find("input[name$='.inHospitalDiseaseStateName']").val();
			  if(inHospitalDiseaseStateCode != ''){
				  	var selectedIndex = $("#update_diag_form select[name$='.inHospitalDiseaseStateCode'] option[value='"+inHospitalDiseaseStateCode+"']").first().index();
					if (selectedIndex == -1) {
						var option = "<option selected value='" + inHospitalDiseaseStateCode + "'>" + inHospitalDiseaseStateName + "</option>";
						$("#update_diag_form select[name$='.inHospitalDiseaseStateCode']").append(option);
					} else {
						$("#update_diag_form select[name$='.inHospitalDiseaseStateCode']").get(0).selectedIndex = selectedIndex;
					}
			  }
			  $("#update_diag_form select[name$='.inHospitalDiseaseStateCode']").next("input[name$='inHospitalDiseaseStateName']").val(inHospitalDiseaseStateName);
			  
			  var treatResultCode = content.find("input[name$='.treatResultCode']").val();
			  var treatResultName = content.find("input[name$='.treatResultName']").val();
			  if(treatResultCode != ''){
				  	var selectedIndex = $("#update_diag_form select[name$='.treatResultCode'] option[value='"+treatResultCode+"']").first().index();
					if (selectedIndex == -1) {
						var option = "<option selected value='" + treatResultCode + "'>" + treatResultName + "</option>";
						$("#update_diag_form select[name$='.treatResultCode']").append(option);
					} else {
						$("#update_diag_form select[name$='.treatResultCode']").get(0).selectedIndex = selectedIndex;
					}
			  }
			  $("#update_diag_form select[name$='.treatResultCode']").next("input[name$='.treatResultName']").val(treatResultName);
			  
			  $("#update_diag_form input[name$='otherDiag.diagSortIndex']").val(content.find("input[name$='.diagSortIndex']").val());
			  var markId = content.find("input[name$='.diagTypeCode']").first().attr("name");
			  $("#update_diag_form a[class='operateBtn']").attr("id",markId);
			  var validator = $("#update_diag_form").validate({
					errorElement: "title",
					ignoreTitle: true,
					submitHandler : function(){
						layerUpdateOtherDiagSubmit(markId);
						/*return false;*/
					},
					rules:{
						/*'otherDiag.diagTypeCode': {
							required: true
			            },
						'otherDiag.diagShow': {
							required: true,
			                minlength: 5
			            },*/
			            'otherDiag.diagSortIndex': {
			            	digits:true,
			            	range:[1,1000]
			            }
						
					},
					
				});
		  }
	});
}
function layerUpdateOtherDiagClick(){
	$("#update_diag_form").submit();
}
function layerUpdateOtherDiagSubmit(markId){
	var content=$("#diseaseDiagInfoForm input[name='"+markId+"']").parent().parent();
	
	
	var diagTypeCode = $("#update_diag_form select[name='otherDiag.diagTypeCode']").val();
	var diagTypeName = $("#update_diag_form input[name='otherDiag.diagTypeName']").val();
	content.find("span[class='otherDiagTypeShow']").html(diagTypeName);
	content.find("input[name$='.diagTypeCode']").val(diagTypeCode);
	content.find("input[name$='.diagTypeName']").val(diagTypeName);
	
	
	var otherDiagCode = $("#update_diag_form input[name='otherDiag.diagCode']").val();
	var otherDiagName = $("#update_diag_form input[name='otherDiag.diagName']").val();
	var otherDiagShow = null;
	if(otherDiagCode==''){
		otherDiagShow=null;
	}else{
		otherDiagShow = otherDiagCode;
	}
	content.find("span[class='otherDiagShow'] ").html(otherDiagShow);
	content.find("input[name$='.diseaseDiagCode']").val(otherDiagCode);
	content.find("input[name$='.diseaseDiagName']").val(otherDiagName);
	
	for (var int = 0; int < 6; int++) {
		var otherExtraDiagCode = $("#update_diag_form input[name='otherExtraDiag"+int+"Code']").val();
		var otherExtraDiagName = $("#update_diag_form input[name='otherExtraDiag"+int+"Name']").val();
		var isChecked = $("#update_diag_form input[name='isExtraMain"+int+"Code']").prop("checked");
		content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val(otherExtraDiagCode);
		content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val(otherExtraDiagName);
		var isExtraMainCode = '1';
		var isExtraMainName = '是';
		if(isChecked){
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(isExtraMainCode);
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(isExtraMainName);
			
		}else{
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(null);
			content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(null);
		}
	}
	
	
	var inHospitalDiseaseStateCode = $("#update_diag_form select[name$='.inHospitalDiseaseStateCode']").val();
	var inHospitalDiseaseStateName = $("#update_diag_form input[name$='.inHospitalDiseaseStateName']").val();
	content.find("span[class='otherDiagInHospitalDiseaseStateShow']").html(inHospitalDiseaseStateName);
	content.find("input[name$='.inHospitalDiseaseStateCode']").val(inHospitalDiseaseStateCode);
	content.find("input[name$='.inHospitalDiseaseStateName']").val(inHospitalDiseaseStateName);
	
	var treatResultCode = $("#update_diag_form select[name$='.treatResultCode']").val();
	var treatResultName = $("#update_diag_form input[name$='.treatResultName']").val();
	content.find("span[class='otherDiagTreatResultShow']").html(treatResultName);
	content.find("input[name$='.treatResultCode']").val(treatResultCode);
	content.find("input[name$='.treatResultName']").val(treatResultName);
	var diagSortIndex = $("#update_diag_form input[name='otherDiag.diagSortIndex']").val();
	content.find("input[name$='.diagSortIndex']").val(diagSortIndex);
	content.find("span[class='otherDiagSortIndex']").html(diagSortIndex);
	layer.close(layerUpdateDiagIndex);
}

//显示修改损伤和中毒的外部原因数据Layer
var layerUpdateDamageDiagIndex
function layerUpdateDamageDiag(obj){
	var basePath = $("#basePath").val();
	var add_content=$("#update_damage_diag_div").clone();
	var content=$(obj).parent().parent();
	add_content.find("form").attr("id","update_damage_diag_form");
	var title = "编辑损伤和中毒的外部原因";
	layerUpdateDamageDiagIndex = layer.open({
		  type: 1,
		  title:title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['820px', '450px'], //宽高
		  offset:'50px',
		  content: add_content.html(),
		  success: function(layero, index){
			  $("#update_damage_diag_form .damageAndVenenationDiagOriginalShow").html(content.find(".damageAndVenenationDiagOriginalShow").html());
			  var damageDiagCode = content.find("input[name='damageAndVenenationDiagRecords[0].diseaseDiagCode']").val();
			  var damageDiagName = content.find("input[name='damageAndVenenationDiagRecords[0].diseaseDiagName']").val();
			  var damageDiagShow = null;
			  if(damageDiagCode==''){
				  damageDiagShow=null;
			  }else{
				  damageDiagShow = damageDiagCode+'['+damageDiagName+']';
			  }
			  $("#update_damage_diag_form input[name='damageAndVenenationDiagShow']").val(damageDiagShow);
			  $("#update_damage_diag_form input[name='damageAndVenenationDiagCode']").val(damageDiagCode);
			  $("#update_damage_diag_form input[name='damageAndVenenationDiagName']").val(damageDiagName);
			  
			  for (var int = 0; int < 6; int++) {
				  var damageAndVenenationExtraDiagCode = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val();
				  var damageAndVenenationExtraDiagName = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val();
				  var damageAndVenenationExtraDiagShow = null;
				  if(damageAndVenenationExtraDiagCode ==''){
					  damageAndVenenationExtraDiagShow = null;
				  }else{
					  damageAndVenenationExtraDiagShow = damageAndVenenationExtraDiagCode+'['+damageAndVenenationExtraDiagName+']';
				  }
				  $("#update_damage_diag_form input[name='damageAndVenenationExtraDiag"+int+"Show']").val(damageAndVenenationExtraDiagShow);
				  $("#update_damage_diag_form input[name='damageAndVenenationExtraDiag"+int+"Code']").val(damageAndVenenationExtraDiagCode);
				  $("#update_damage_diag_form input[name='damageAndVenenationExtraDiag"+int+"Name']").val(damageAndVenenationExtraDiagName);
				  
				  var isExtraMainCode = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val();
				  if(isExtraMainCode && isExtraMainCode == '1'){
					  $("#update_damage_diag_form input[name='isExtraMain"+int+"Code']").prop("checked",true);;
					  
				  }
			  }
			  $.each($("#update_damage_diag_form input[data-type='diseaseDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_injury_poisoning_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  
			  $.each($("#update_damage_diag_form input[data-type='allDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_all_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  var validator = $("#update_damage_diag_form").validate({
					errorElement: "title",
					ignoreTitle: true,
					submitHandler : function(){
						layerUpdateDamageSubmit();
						/*return false;*/
					},
					/*rules:{
						'damageAndVenenationDiagShow': {
							required: true,
			                minlength: 5
			            }
						
					},*/
					
				});
		  }
		});
}

function layerUpdateDamageClick(){
	$("#update_damage_diag_form").submit();
}

function layerUpdateDamageSubmit(){
	var damageAndVenenationDiagCode = $("#update_damage_diag_form input[name='damageAndVenenationDiagCode']").val();
	var damageAndVenenationDiagName = $("#update_damage_diag_form input[name='damageAndVenenationDiagName']").val();
	var damageAndVenenationDiagShow = null;
	if(damageAndVenenationDiagCode==''){
		damageAndVenenationDiagShow=null;
	}else{
		damageAndVenenationDiagShow = damageAndVenenationDiagCode;
	}
	$("#diseaseDiagInfoForm span[class='damageAndVenenationDiagShow']").html(damageAndVenenationDiagShow);
	$("#diseaseDiagInfoForm input[name='damageAndVenenationDiagRecords[0].diseaseDiagName']").val(damageAndVenenationDiagName);
	$("#diseaseDiagInfoForm input[name='damageAndVenenationDiagRecords[0].diseaseDiagCode']").val(damageAndVenenationDiagCode);
	
	for (var int = 0; int < 6; int++) {
		var damageAndVenenationExtraDiagCode = $("#update_damage_diag_form input[name='damageAndVenenationExtraDiag"+int+"Code']").val();
		var damageAndVenenationExtraDiagName = $("#update_damage_diag_form input[name='damageAndVenenationExtraDiag"+int+"Name']").val();
		$("#diseaseDiagInfoForm input[name='damageAndVenenationDiagRecords[0].diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val(damageAndVenenationExtraDiagCode);
		$("#diseaseDiagInfoForm input[name='damageAndVenenationDiagRecords[0].diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val(damageAndVenenationExtraDiagName);
		var isChecked = $("#update_damage_diag_form input[name='isExtraMain"+int+"Code']").prop("checked");
		var isExtraMainCode = '1';
		var isExtraMainName = '是';
		if(isChecked){
			$("#diseaseDiagInfoForm input[name='damageAndVenenationDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(isExtraMainCode);
			$("#diseaseDiagInfoForm input[name='damageAndVenenationDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(isExtraMainName);
			
		}else{
			$("#diseaseDiagInfoForm [name='damageAndVenenationDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(null);
			$("#diseaseDiagInfoForm [name='damageAndVenenationDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(null);
		}
	}
	
	
	
	layer.close(layerUpdateDamageDiagIndex);
}


//显示修改病理学数据Layer
var layerUpdatePathologyDiagIndex
function layerUpdatePathologyDiag(obj){
	var basePath = $("#basePath").val();
	var add_content=$("#update_pathology_diag_div").clone();
	var content=$(obj).parent().parent();
	add_content.find("form").attr("id","update_pathology_diag_form");
	var title = "编辑形态学编码";
	layerUpdatePathologyDiagIndex = layer.open({
		  type: 1,
		  title:title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['820px', '470px'], //宽高
		  offset:'50px',
		  content: add_content.html(),
		  success: function(layero, index){
			  $("#update_pathology_diag_form .pathologyDiagOriginalShow").html(content.find(".pathologyDiagOriginalShow").html());
			  var pathologyDiagCode = content.find("input[name='pathologyDiagRecords[0].diseaseDiagCode']").val();
			  var pathologyDiagName = content.find("input[name='pathologyDiagRecords[0].diseaseDiagName']").val();
			  var pathologyDiagShow = null;
			  if(pathologyDiagCode==''){
				  pathologyDiagShow=null;
			  }else{
				  pathologyDiagShow = pathologyDiagCode+'['+pathologyDiagName+']';
			  }
			  $("#update_pathology_diag_form input[name='pathologyDiagShow']").val(pathologyDiagShow);
			  $("#update_pathology_diag_form input[name='pathologyDiagCode']").val(pathologyDiagCode);
			  $("#update_pathology_diag_form input[name='pathologyDiagName']").val(pathologyDiagName);
			  
			  for (var int = 0; int < 6; int++) {
				  var pathologyExtraDiagCode = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val();
				  var pathologyExtraDiagName = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val();
				  var pathologyExtraDiagShow = null;
				  if(pathologyExtraDiagCode ==''){
					  pathologyExtraDiagShow = null;
				  }else{
					  pathologyExtraDiagShow = pathologyExtraDiagCode+'['+pathologyExtraDiagName+']';
				  }
				  $("#update_pathology_diag_form input[name='pathologyExtraDiag"+int+"Show']").val(pathologyExtraDiagShow);
				  $("#update_pathology_diag_form input[name='pathologyExtraDiag"+int+"Code']").val(pathologyExtraDiagCode);
				  $("#update_pathology_diag_form input[name='pathologyExtraDiag"+int+"Name']").val(pathologyExtraDiagName);

				  var isExtraMainCode = content.find("input[name$='.diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val();
				  if(isExtraMainCode && isExtraMainCode == '1'){
					  $("#update_pathology_diag_form input[name='isExtraMain"+int+"Code']").prop("checked",true);;
					  
				  }
			  }
			  
			  var pathologyNumber = content.find("input[name$='.pathologyNumber']").val();
			  $("#update_pathology_diag_form input[name='pathologyNumber']").val(pathologyNumber);
			  
			  $.each($("#update_pathology_diag_form input[data-type='diseaseDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_morphology_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  
			  $.each($("#update_pathology_diag_form input[data-type='allDiag']"),function(i,item) {
					$(item).autocomplete({
						source: function( request, response ) {
							var eventObj = $(this.element);
							
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
							$.ajax({
								url: basePath + "base_info/ajax_all_diseases_by_query_name",
								dataType: "json",
								data:{
									queryName: request.term
								},
								success: function( data ) {
									if(data.length > 0){
										response( $.map( data, function( item ) {
											return {
												label:item.uniq_code+'['+item.label+']',
												uniq_code:item.uniq_code,
												uniq_name:item.label
											}
										}));
									}else{
										response([[]]);
									}
								}
							});
						},
						minLength: 2,
						select: function( event, ui ) {
							var eventObj = $(this);
							var item = ui.item;
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
						},search: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							eventObj.nextAll("input[name='"+codeObjName+"']").val("");
							
							var nameObjName = eventObj.attr("name").replace("Show", "Name");
							eventObj.nextAll("input[name='"+nameObjName+"']").val("");
							
						},change: function( event, ui ) {
							if(ui.item == null){
								var eventObj = $(this);
								var codeObjName = eventObj.attr("name").replace("Show", "Code");
								eventObj.nextAll("input[name='"+codeObjName+"']").val(null);
								var nameObjName = eventObj.attr("name").replace("Show", "Name");
								eventObj.nextAll("input[name='"+nameObjName+"']").val(null);
							}
					    },
						close: function( event, ui ) {
							var eventObj = $(this);
							var codeObjName = eventObj.attr("name").replace("Show", "Code");
							var codeValue = eventObj.nextAll("input[name='"+codeObjName+"']").val();
							if(!codeValue){
								eventObj.val(null);
							}
					    }
					});
				});
			  
			  var validator = $("#update_pathology_diag_form").validate({
					errorElement: "title",
					ignoreTitle: true,
					submitHandler : function(){
						layerUpdatePathologySubmit();
						/*return false;*/
					},
					/*rules:{
						'pathologyDiagShow': {
							required: true,
			                minlength: 5
			            }
						
					},*/
					
				});
		  }
		});
}

function layerUpdatePathologyClick(){
	$("#update_pathology_diag_form").submit();
}

function layerUpdatePathologySubmit(){
	var pathologyDiagCode = $("#update_pathology_diag_form input[name='pathologyDiagCode']").val();
	var pathologyDiagName = $("#update_pathology_diag_form input[name='pathologyDiagName']").val();
	var pathologyDiagShow = null;
	if(pathologyDiagCode==''){
		pathologyDiagShow=null;
	}else{
		pathologyDiagShow = pathologyDiagCode;
	}
	$("#diseaseDiagInfoForm span[class='pathologyDiagShow']").html(pathologyDiagShow);
	$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].diseaseDiagName']").val(pathologyDiagName);
	$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].diseaseDiagCode']").val(pathologyDiagCode);
	
	for (var int = 0; int < 6; int++) {
		var pathologyExtraDiagCode = $("#update_pathology_diag_form input[name='pathologyExtraDiag"+int+"Code']").val();
		var pathologyExtraDiagName = $("#update_pathology_diag_form input[name='pathologyExtraDiag"+int+"Name']").val();
		$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].diseaseExtraDiagRecords["+int+"].diseaseExtraDiagCode']").val(pathologyExtraDiagCode);
		$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].diseaseExtraDiagRecords["+int+"].diseaseExtraDiagName']").val(pathologyExtraDiagName);
		var isChecked = $("#update_pathology_diag_form input[name='isExtraMain"+int+"Code']").prop("checked");
		var isExtraMainCode = '1';
		var isExtraMainName = '是';
		if(isChecked){
			$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(isExtraMainCode);
			$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(isExtraMainName);
			
		}else{
			$("#diseaseDiagInfoForm [name='pathologyDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainCode']").val(null);
			$("#diseaseDiagInfoForm [name='pathologyDiagRecords[0].diseaseExtraDiagRecords["+int+"].isExtraMainName']").val(null);
		}
	}
	
	
	var pathologyNumber = $("#update_pathology_diag_form input[name='pathologyNumber']").val();
	$("#diseaseDiagInfoForm input[name='pathologyDiagRecords[0].pathologyNumber']").val(pathologyNumber);
	$("#diseaseDiagInfoForm span[class='pathologyNumberShow']").html("病理号:"+pathologyNumber)
	layer.close(layerUpdatePathologyDiagIndex);
}

function clearPathologyOriginalDiag(obj){
	var content = $(obj);
	content.parent().find("span[class='pathologyDiagOriginalShow']").html(null);
	$("span[class='pathologyDiagOriginalShow']").html(null);
	$("input[name='pathologyDiagRecords[0].diseaseDiagOriginalDesc']").val(null);
	$("input[name='pathologyDiagRecords[0].diseaseDiagOriginalCode']").val(null);
}

function clearDamageAndVenenationOriginalDiag(obj){
	var content = $(obj);
	content.parent().find("span[class='damageAndVenenationDiagOriginalShow']").html(null);
	$("span[class='damageAndVenenationDiagOriginalShow']").html(null);
	$("input[name='damageAndVenenationDiagRecords[0].diseaseDiagOriginalDesc']").val(null);
	$("input[name='damageAndVenenationDiagRecords[0].diseaseDiagOriginalCode']").val(null);
}